/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Validation;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**

 @author jtanguay
 */
@FacesValidator("ValidateApparence")
public class ValidateAppearance implements Validator {

  @Override
  public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    FacesMessage fMsg;

    if (((String) value).length() < 5) {
      fMsg = new FacesMessage("The apparence must contain at least 5 caracters.");
      fMsg.setSeverity(FacesMessage.SEVERITY_ERROR);

      throw new ValidatorException(fMsg);
    } else if (((String) value).length() > 45) {
      fMsg = new FacesMessage("The appearance must contain a maximum of 45 characters.");
      fMsg.setSeverity(FacesMessage.SEVERITY_ERROR);

      throw new ValidatorException(fMsg);
    }
  }
}
